﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Elentok.Common.Wpf.ViewModels.Dialogs
{
  /// <summary>
  /// The view model for an exception dialog
  /// </summary>
  public class ExceptionDialogViewModel : DialogViewModelBase
  {
    #region Fields

    private Exception exception;
    private string message;

    #endregion

    #region Ctor

    /// <summary>
    /// Initializes a new instance of the <see cref="ExceptionDialogViewModel"/> class.
    /// </summary>
    /// <param name="exception">The exception.</param>
    public ExceptionDialogViewModel(Exception exception)
      : this(exception, exception.Message) { }

    /// <summary>
    /// Initializes a new instance of the <see cref="ExceptionDialogViewModel"/> class.
    /// </summary>
    /// <param name="exception">The exception.</param>
    /// <param name="customMessage">The custom message.</param>
    public ExceptionDialogViewModel(Exception exception, string customMessage)
    {
      this.Exception = exception;
      this.Message = customMessage;
      this.Title = "An error has occured";
    }

    #endregion

    #region Properties

    /// <summary>
    /// Gets or sets the exception.
    /// </summary>
    /// <value>The exception.</value>
    public Exception Exception
    {
      get
      {
        return this.exception;
      }
      set
      {
        if (this.exception == value)
          return;

        OnPropertyChanging("Exception");
        this.exception = value;
        OnPropertyChanged("Exception");
      }
    }

    /// <summary>
    /// Gets or sets the message
    /// </summary>
    public string Message
    {
      get
      {
        return this.message;
      }
      set
      {
        if (this.message == value)
          return;

        OnPropertyChanging("Message");
        this.message = value;
        OnPropertyChanged("Message");
      }
    }

    #endregion
  }
}
